package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendPeopleMonthlyStatAddDTO;
import org.jsola.hr.dto.AttendPeopleMonthlyStatUpdateDTO;
import org.jsola.hr.entity.AttendPeopleMonthlyStatDO;
import org.jsola.hr.query.AttendPeopleMonthlyStatQuery;
import org.jsola.hr.service.IAttendPeopleMonthlyStatService;
import org.jsola.hr.vo.AttendPeopleMonthlyStatVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendPeopleMonthlyStatTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendPeopleMonthlyStatService attendPeopleMonthlyStatService;

    /**
     * 生成add测试数据
     * @return AttendPeopleMonthlyStatAddDTO
     */
    public AttendPeopleMonthlyStatAddDTO getAttendPeopleMonthlyStatAddDTO(){
        AttendPeopleMonthlyStatAddDTO attendPeopleMonthlyStatAddDTO = new AttendPeopleMonthlyStatAddDTO();
        attendPeopleMonthlyStatAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendPeopleMonthlyStatAddDTO.setCompanyName(getRandomValue("varchar",100));
        attendPeopleMonthlyStatAddDTO.setDeptId(getRandomValue("varchar",32));
        attendPeopleMonthlyStatAddDTO.setDeptName(getRandomValue("varchar",50));
        attendPeopleMonthlyStatAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        attendPeopleMonthlyStatAddDTO.setEmpInfoId(getRandomValue("varchar",32));
        attendPeopleMonthlyStatAddDTO.setEmpInfoName(getRandomValue("varchar",50));
        attendPeopleMonthlyStatAddDTO.setJobNumber(getRandomValue("varchar",50));
        attendPeopleMonthlyStatAddDTO.setYearly(getRandomValue("varchar",10));
        attendPeopleMonthlyStatAddDTO.setMonthly(getRandomValue("varchar",10));
        attendPeopleMonthlyStatAddDTO.setShouldWorkDays(SafeKit.getInteger(getRandomValue("int",0)));
        attendPeopleMonthlyStatAddDTO.setAttendDays(SafeKit.getInteger(getRandomValue("int",0)));
        attendPeopleMonthlyStatAddDTO.setRestDays(SafeKit.getInteger(getRandomValue("int",0)));
        attendPeopleMonthlyStatAddDTO.setLateCounts(SafeKit.getInteger(getRandomValue("int",0)));
        attendPeopleMonthlyStatAddDTO.setOnWorkMissCounts(SafeKit.getInteger(getRandomValue("int",0)));
        attendPeopleMonthlyStatAddDTO.setOffWorkMissCounts(SafeKit.getInteger(getRandomValue("int",0)));
        attendPeopleMonthlyStatAddDTO.setAbsenteeismDays(SafeKit.getBigDecimal(getRandomValue("decimal",3)));
        attendPeopleMonthlyStatAddDTO.setLeaveDays(SafeKit.getBigDecimal(getRandomValue("decimal",3)));
        return attendPeopleMonthlyStatAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendPeopleMonthlyStatUpdateDTO
     */
    public AttendPeopleMonthlyStatUpdateDTO getAttendPeopleMonthlyStatUpdateDTO(AttendPeopleMonthlyStatVO attendPeopleMonthlyStatVO){
        return attendPeopleMonthlyStatService.selectDOById(attendPeopleMonthlyStatVO.getId(), SITE_ID).to(AttendPeopleMonthlyStatUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendPeopleMonthlyStatQuery
     */
    public AttendPeopleMonthlyStatQuery getAttendPeopleMonthlyStatQuery() {
        AttendPeopleMonthlyStatQuery attendPeopleMonthlyStatQuery = new AttendPeopleMonthlyStatQuery();
        List<AttendPeopleMonthlyStatDO> attendPeopleMonthlyStatDOList = attendPeopleMonthlyStatService.list(new AttendPeopleMonthlyStatDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendPeopleMonthlyStatDOList)) {
            AttendPeopleMonthlyStatDO attendPeopleMonthlyStatDO = attendPeopleMonthlyStatDOList.get(0);
            attendPeopleMonthlyStatQuery = attendPeopleMonthlyStatDO.to(AttendPeopleMonthlyStatQuery.class);
            if (attendPeopleMonthlyStatDO.getAbsenteeismDays() != null) {
                attendPeopleMonthlyStatQuery.setAbsenteeismDaysStart(attendPeopleMonthlyStatDO.getAbsenteeismDays().subtract(new BigDecimal(1)));
                attendPeopleMonthlyStatQuery.setAbsenteeismDaysEnd(attendPeopleMonthlyStatDO.getAbsenteeismDays().add(new BigDecimal(1)));
            }
            if (attendPeopleMonthlyStatDO.getLeaveDays() != null) {
                attendPeopleMonthlyStatQuery.setLeaveDaysStart(attendPeopleMonthlyStatDO.getLeaveDays().subtract(new BigDecimal(1)));
                attendPeopleMonthlyStatQuery.setLeaveDaysEnd(attendPeopleMonthlyStatDO.getLeaveDays().add(new BigDecimal(1)));
            }
            if (attendPeopleMonthlyStatDO.getGmtCreate() != null) {
                attendPeopleMonthlyStatQuery.setGmtCreateStart(DateKit.getBeforeDay(attendPeopleMonthlyStatDO.getGmtCreate(),-1));
                attendPeopleMonthlyStatQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendPeopleMonthlyStatDO.getGmtCreate(),1));
            }
            if (attendPeopleMonthlyStatDO.getGmtModified() != null) {
                attendPeopleMonthlyStatQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendPeopleMonthlyStatDO.getGmtModified(),-1));
                attendPeopleMonthlyStatQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendPeopleMonthlyStatDO.getGmtModified(),1));
            }
        }
        return attendPeopleMonthlyStatQuery;
    }

    /**
     * 保存示例
     * @return AttendPeopleMonthlyStatVO
     */
    public AttendPeopleMonthlyStatVO saveAttendPeopleMonthlyStatExample(){
        AttendPeopleMonthlyStatAddDTO addDTO = this.getAttendPeopleMonthlyStatAddDTO();
        AttendPeopleMonthlyStatVO attendPeopleMonthlyStatVO = attendPeopleMonthlyStatService.save(addDTO,buildTokenUser());
        return attendPeopleMonthlyStatVO;
    }


}

